using GLib;
using Gtk;

namespace Zoo
{

public class TargetSelector : Table
{
    private Scratchbox* sbox;

    private ComboBox target;
    private ListStore target_model;

    private Entry architecture;
    private Entry compiler;
    private Entry transparency;

    public signal void target_changed(string target_name);

    public TargetSelector(ref Scratchbox sbox)
    {
        homogeneous = false;
        n_columns = 4;
        n_rows = 2;
        column_spacing = 4;
        row_spacing = 4;
        border_width = 4;

        target_model = new ListStore(1, typeof(string));
        target = new ComboBox.with_model(target_model);
        var renderer = new CellRendererText();
        target.pack_start(renderer, true);
        target.add_attribute(renderer, "text", 0);

        architecture = new Entry();
        architecture.editable = false;
        compiler = new Entry();
        compiler.editable = false;
        transparency = new Entry();
        transparency.editable = false;

        attach(new Label("Target"), 0, 1, 0, 1,
               AttachOptions.SHRINK,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);
        attach(target, 1, 2, 0, 1,
               AttachOptions.EXPAND|AttachOptions.FILL,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);
        attach(new Label("Architecture"), 0, 1, 1, 2,
               AttachOptions.SHRINK,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);
        attach(architecture, 1, 2, 1, 2,
               AttachOptions.FILL,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);
        attach(new Label("Compiler"), 0, 1, 2, 3,
               AttachOptions.SHRINK,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);
        attach(compiler, 1, 2, 2, 3,
               AttachOptions.FILL,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);
        attach(new Label("Transparency"), 0, 1, 3, 4,
               AttachOptions.SHRINK,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);
        attach(transparency, 1, 2, 3, 4,
               AttachOptions.FILL,
               AttachOptions.EXPAND|AttachOptions.FILL,
               0, 0);

        this.sbox = sbox;
        this.sbox->scratchbox_dir_changed.connect(this.update_info);
        this.update_info();
    }

    public void update_info()
    {
        string current = sbox->current_target_name();
        target_model.clear();
        foreach (string t_name in sbox->get_target_names()) {
            TreeIter iter;
            target_model.append(out iter);
            target_model.set(iter, 0, t_name);
            if (t_name == current)
                target.set_active_iter(iter);
        }
        architecture.text = "arm";
        compiler.text = "gcc";
        transparency.text = "qemu";

    }
}

} // namespace Zoo

